#!/usr/bin/env python
# -*- coding: utf-8 -*-

""" Calculate Orthodox Easter date for the given year.
    I've borrowed JavaScript code from the Internet
    and made this module. Hope this helps someone.
"""

import math

class Calc_p():

    def mod(self, x, y):
        r = x-(math.floor(x/y)*y)
        return r

#    def mt(self, x):
#        # return month name, actually useless. Can be safely deleted.
#        if x == 3: 
#            r = " марта"
#        elif x == 4: 
#            r = " апреля"
#        else: 
#            r = " мая"
#        return r

    def gogo(self, y1): 
        a = self.mod(y1, 19)
        b = self.mod(y1, 4)
        c = self.mod(y1, 7)
        d = self.mod((19*a+15), 30)
        e = self.mod((2*b+4*c+6*d+6), 7)
        if d+e <= 9:
            d1=22+d+e
            m1=3
        else:
            d1=d+e-9
            m1=4

        # some adjustments, old-new style
        if d1==26 and m1==4:
            d1=19
        if d==28 and e==6:
            d1=18
        if m1==3:
            d2=d1-18
            m2=4
        elif d1<=17:
            d2=d1+13
            m2=4
        else:
            d2=d1-18
            m2=5

#        return (math.trunc(d2), m2, math.trunc(d1), m1, y1)
        p_day = math.trunc(d2) 
        if p_day == 0:
            p_day = 1
            
#        return (math.trunc(d2), m2, y1)
        return (p_day, m2, y1)

if __name__ == '__main__':

    import sys
    argv = sys.argv

    if len(argv) > 1:
        y1 = int(argv[1])
    else:
        print 'No args given, exiting'
        raise SystemExit

    Calc = Calc_p()
    res = Calc.gogo(y1)
    new_day = res[0]
    new_month = res[1]
    old_day = res[2]
    old_month = res[3]
    year = res[4]

    print new_day, new_month, year, 'по новому стилю'
    print old_day, old_month, year, 'по старому стилю'

